package cn.edu.njust.service.impl;

import cn.edu.njust.mapper.RegisterMapper;
import cn.edu.njust.mapper.UserMapper;
import cn.edu.njust.pojo.Register;
import cn.edu.njust.service.reService;
import cn.edu.njust.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class reServiceImpl implements reService {
    // 获取工厂对象
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public List<Register> selectAllRe() {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取UserMapper
        RegisterMapper mapper = sqlSession.getMapper(RegisterMapper.class);

        List<Register> res = mapper.selectAllRe();

        sqlSession.close();

        return res;

    }

    @Override
    public void approveById(String idNo) {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取UserMapper
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用方法
        mapper.approveById01(idNo);

        sqlSession.commit();

        sqlSession.close();
    }

    @Override
    public void disapproveById(String idNo) {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取UserMapper
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用方法
        mapper.disapproveById01(idNo);

        sqlSession.commit();

        sqlSession.close();
    }
}
